package com.xueshan.disruptor.common.producer.impl;

import com.lmax.disruptor.RingBuffer;
import com.xueshan.disruptor.common.event.MessageModel;
import com.xueshan.disruptor.common.producer.MqService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * created with IDEA
 *
 * @author:huqm
 * @date:2021/3/13
 * @time:22:19 <p>
 *
 * </p>
 */
@Component
@Slf4j
public class MqServiceImpl implements MqService {

    @Resource
    private RingBuffer<MessageModel> messageModelRingBuffer;

    @Override
    public void sayHelloMq(long value) {
        log.info("开始时间{}",System.currentTimeMillis());
        for(int i=0;i<1024*1024*500;i++) {
            long sequence = messageModelRingBuffer.next();
            try {
                messageModelRingBuffer.get(sequence).setValue(value);
            } catch (Exception e) {

            } finally {
                messageModelRingBuffer.publish(sequence);
            }
        }
        log.info("生产者开始完成发布");

    }

    @Override
    public void userReg(Long userId) {

    }
}
